package com.itheima.jobs;

import com.itheima.constant.RedisConstant;
import com.itheima.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import redis.clients.jedis.JedisPool;

import java.util.Set;

/**
 * @Author: bowen
 * @Date: 2019/7/14 18:24
 * @Description:
 */
public class ClearRubbish {


	@Autowired
	JedisPool jedisPool;


	public void clearImg(){
	//	两个set取差值
		Set<String> sdiff = jedisPool.getResource().
				sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);

		if(!CollectionUtils.isEmpty(sdiff)){
			sdiff.forEach(item->{
				System.out.println("delete:"+item);
				//	遍历set，逐条删除七牛云上面的图片
				QiniuUtils.deleteFileFromQiniu(item);
				//	清空redis垃圾信息
				jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,item);
			});

		}


	}
}
